package eli.turchinsky.software.agame.hood;

import android.util.Log;

public class Vector2 {
	public final static Vector2 Zero=new Vector2(0,0);
	private float _x;
	private float _y;
	public float getX(){
		return _x;
	}
	public float getY(){
		return _y;
	}
	public Vector2(){
		_x=0;
		_y=0;
	}
	public Vector2(float x,float y){
		_x=x;
		_y=y;
	}
	public Vector2 set(float x,float y){
		_x=x;
		_y=y;
		return this;
	}	
	public Vector2 add(Vector2 v){
		_x+=v.getX();
		_y+=v.getY();
		return this;		
	}
	public Vector2 addNew(Vector2 v){
		Vector2 t=new Vector2(_x,_y);
		t._x+=v.getX();
		t._y+=v.getY();
		return t;		
	}
	public Vector2 sub(Vector2 v){
		_x-=v.getX();
		_y-=v.getY();
		return this;		
	}
	public Vector2 mul(float f){
		Vector2 v=new Vector2(_x,_y);
		v._x*=f;
		v._y*=f;
		return v;
	}
	public Vector2 dot(Vector2 v){
		return new Vector2(getX()*v.getX(),getY()*v.getY());		
	}
	public float cross(Vector2 v){
		return getX()*v.getY()-v.getX()*getY();
	}
	public float distance(Vector2 v){
		return android.util.FloatMath.sqrt((float) (Math.pow(_x-v.getX(), 2)+Math.pow(_y-v.getY(), 2)));
	}
	public float length(){
		return android.util.FloatMath.sqrt((float) (Math.pow(_x, 2)+Math.pow(_x, 2)));
	}
	public Vector2 normalize(){
		float len=length();		
		if(len!=0){
			_x/=len;
			_y/=len;
		}
		return this;
	}
	public Vector2 angleDif(Vector2 v){
		Vector2 my=new Vector2(getX(),getY());
		return my.sub(v).normalize();				
	}
	public Vector2 angleDifNeg(Vector2 v){
		Vector2 my=angleDif(v);
		return my.set(my.getX()*-1, my.getY()*-1);
	}
	public Vector2 getOrthogonal(){
		return new Vector2(_y,-_x);
	}
}
